package com.bitdf.txing.product.controller;


import cn.dev33.satoken.annotation.SaCheckLogin;
import cn.dev33.satoken.annotation.SaCheckPermission;
import com.bitdf.txing.common.utils.R;
import com.bitdf.txing.common.valid.SaveGroup;
import com.bitdf.txing.common.valid.UpdateGroup;
import com.bitdf.txing.product.entity.BrandEntity;
import com.bitdf.txing.product.service.BrandService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.Arrays;
import java.util.List;


/**
 * 品牌
 *
 * @author lizhiwei
 * @email sunlightcs@gmail.com
 * @date 2022-05-16 20:22:24
 */
@RestController
@RequestMapping("${txing.request.path.product}/brand")
public class BrandController {
    @Autowired
    private BrandService brandService;


    /**
     * 根据ids查出品牌信息
     * @param brandIds
     * @return
     */
    @RequestMapping("/infos")
    public R info(@RequestParam("brandIds") List<Long> brandIds){
        List<BrandEntity> brand = brandService.getBrandsByIds(brandIds);
        return R.ok().put("brand", brand);
    }

    /**
     * 列表
     */
//    @RequestMapping("/list")
//    public R list(@RequestParam Map<String, Object> params){
//        PageUtils page = brandService.queryPage(params);
//
//        return R.ok().put("page", page);
//    }


    /**
     * 信息
     */
    @RequestMapping("/info/{brandId}")
    public R info(@PathVariable("brandId") Long brandId){
		BrandEntity brand = brandService.getById(brandId);
        return R.ok().put("brand", brand);
    }

    /**
     * 添加品牌
     */
    @SaCheckLogin
    @SaCheckPermission("mall:product:brand:add")
    @RequestMapping("/save")
    public R save(@Validated({SaveGroup.class}) @RequestBody BrandEntity brand){
        brandService.save(brand);
        return R.ok();
    }

    /**
     * 修改
     */
    @SaCheckLogin
    @SaCheckPermission("mall:product:brand:update")
    @RequestMapping("/update")
    public R update(@Validated({UpdateGroup.class}) @RequestBody BrandEntity brand){
		brandService.updateDetail(brand);

        return R.ok();
    }

//    @RequestMapping("/update/status")
//    public R updateStatus(@Validated({UpdateStatusGroup.class}) @RequestBody BrandEntity brand){
//        brandService.updateById(brand);
//
//        return R.ok();
//    }

    /**
     * 删除
     */
    @SaCheckLogin
    @SaCheckPermission("mall:product:brand:delete")
    @RequestMapping("/delete")
    public R delete(@RequestBody Long[] brandIds){
		brandService.removeByIds(Arrays.asList(brandIds));
        return R.ok();
    }

}
